<%@page import="com.dxl.common.utils.Utils"%>
<%@page import="com.dxl.service.account.AccountService"%>
<%@page import="com.dxl.common.spring.AppCtxHolder"%>
<%@page import="com.dxl.common.consts.SysConsts"%>
<%@page import="com.dxl.web.common.utils.RequestUtils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%>
<%@ include file="/WEB-INF/view/common/import.jspf" %>
<%
	String sessionId = RequestUtils.getValueFromRequest(request, SysConsts.LOGINED_SESSION_ID_KEY);
	if (Utils.isNotBlank(sessionId)
		&& Utils.isNotNull(AppCtxHolder.getBean(AccountService.class).login(sessionId, null, null))) {
		response.sendRedirect((String)request.getAttribute("ROOT"));
		return;
	}
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=8" />
	<title>榄菊开单系统</title>
	<link rel="stylesheet" type="text/css" href="${ROOT}/static/js/easyui/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${ROOT}/static/js/easyui/themes/icon.css" />
	<style type="text/css">
		.loginDiv {
			margin-left: auto; 
			margin-right: auto;
			margin-top:300px;
			width:350px;
			height:150px;
			border: solid 1px #DFDFDF;
		}
	</style>
</head>
<body>
	<div class="loginDiv">
		<div class="easyui-panel" data-options="fit:true,footer:'#loginBtns'" style="padding:10px;">
		    <form method="post" id="loginForm">
		    	<br/>
	            <table>
		             <tr>
		                 <td>账号:</td>
		                 <td>
		                 	<input class="easyui-textbox" style="width:200px;" type="text" name="account" id="account" data-options="prompt:'账号、手机或者邮箱', required:true" />
		                 </td>
		             </tr>
		             <tr>
		                 <td>密码:</td>
		                 <td>
		                 	<input class="easyui-textbox" style="width:200px;" type="password" name="password" id="password" data-options="required:true" />
		                 </td>
		             </tr>
		         </table>
		    </form> 
		</div>
	</div>
	<div id="loginBtns" style="text-align:right;padding:2px;">
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="login();">登录</a>
	</div>
	
	<script type="text/javascript" src="${ROOT}/static/js/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="${ROOT}/static/js/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${ROOT}/static/js/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="${ROOT}/static/js/common/common.js"></script>
	<script type="text/javascript">
		$(function () {
			$('#loginForm').form({
			    url:'${ROOT}/login?_rt=' + new Date().getTime(),
			    ajax: true,
			    onSubmit: function() {
			    	return $(this).form('enableValidation').form('validate');
			    },
			    success:function(data) {
			    	var json = eval('(' + data + ')');
					if (json.success) {
						APP.message('登录成功');
						if (window.parent) {
							window.parent.location.href = '${ROOT}';
						} else {
							window.location.href = '${ROOT}';
						}
			        } else {
			        	APP.error(json.msg);
			        }
			    }
			});
			$('#account').textbox('textbox').bind('keydown', function(e){
				if (e.keyCode == 13) {
					login();
				}
			});
			$('#password').textbox('textbox').bind('keydown', function(e){
				if (e.keyCode == 13) {
					login();
				}
			});
		});
		
		function login() {
			$('#loginForm').submit();
		}
	</script>
</body>
</html>